package com.UBC417.termproject.Servlet;

import java.io.IOException;
import java.util.logging.Logger;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.UBC417.termproject.Data.Buyer;
import com.UBC417.termproject.Data.Comment;

@SuppressWarnings("serial")
public class RateSellerServlet extends HttpServlet{
private static final Logger log = Logger.getLogger(SubscribeServlet.class.getName());
	
	public void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws IOException, ServletException {
		
		HttpSession session = req.getSession();
		String buyerId = (String) session.getAttribute("id");
		// Get parameters		
		String sellerId = req.getParameter("sellerId");
		String rating = req.getParameter("rate");
		String comment = req.getParameter("comment");
		
		Comment c;
		Double r;
		log.info("sellerId: "+ sellerId);
		log.info ("rating: "+ rating);
		
		Buyer.SetRating(buyerId,sellerId, rating);
		
		if (comment!=""){
			c=Buyer.SetComment(buyerId, sellerId, comment);
			log.info ("comment: "+ comment);
		}
		// TODO: show seller new rating
		
		// TODO: show seller new comment
		
		// redirect to user page
        String forwardTo = "/buyer.jsp";
		ServletContext sc = getServletContext();
		RequestDispatcher rd = sc.getRequestDispatcher(forwardTo);
		rd.forward(req, resp);
	}

}
